//
//  LivePushTableViewController.m
//  彩票项目
//
//  Created by 伍银荣 on 2021/8/5.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "LivePushTableViewController.h"
#import "UIView+Frame.h"

@interface LivePushTableViewController ()

@property (nonatomic, weak) UIDatePicker *datePicker;
@end

@implementation LivePushTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark - Table view data source
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"点击了cell");
    if (indexPath.section == 0) {
        return;
    }
    //创建textField
    UITextField *textField = [[UITextField alloc]init];
    textField.backgroundColor = [UIColor yellowColor];
    //添加到cell上
    //获取cell
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell.contentView addSubview:textField];
    
    //创建dataPick对象
    UIDatePicker *picker = [[UIDatePicker alloc]init];
    //设置中文
    picker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh-CN"];
    //设置时间格式
    picker.datePickerMode = UIDatePickerModeTime;
    //设置inputView
    textField.inputView = picker;
    self.datePicker = picker;
    
    //创建toolBar
    UIToolbar *bar = [[UIToolbar alloc]init];
    bar.h = 44;
    UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelClick)];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(doneClick)];
    bar.items = @[cancelItem, item, doneItem];
    textField.inputAccessoryView = bar;

    //让键盘成为第一响应者
    [textField becomeFirstResponder];
}

- (void)cancelClick {
    //收回键盘
    [self.view endEditing:YES];
}

- (void)doneClick {
    //获取datePicker的时间
    NSDate *date = self.datePicker.date;
    //创建时间格式对象
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    //设置时间格式化对象的格式
    formatter.dateFormat = @"HH:mm";
    NSString *time = [formatter stringFromDate:date];
    //获取cell
    //获取indxPath对象
    NSIndexPath *indxPath = [self.tableView indexPathForSelectedRow];
    //获取cell
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indxPath];
    cell.detailTextLabel.text = time;
    //收回键盘
    [self cancelClick];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
